package Biblioteca

abstract class Item {
    int id
    String titulo
    String autores
    String ano
    
    static constraints = {
        id(blank: false, unique: true, maxSize:30)
        titulo(blank: false, maxSize:100, validator: {return isTitle(it)})
        autores(blank: false, validator: {return isAutorValido(it)})
		ano(blank: false)
    }
	
	public static boolean isAutorValido (String name){
		def expressaoRegular = /([a-zA-Z\p{L}, ]+)/
		return (name ==~ expressaoRegular)
		
	}
	
	public static boolean isTitle (String name){
		def expressaoRegular = /([a-zA-Z\p{L}0-9,:.''""*&@! ]+)/
		return (name ==~ expressaoRegular)
	}
}
